import pymysql

class DB:

    def __init__(self) -> None:
        self.conn = pymysql.connect(
            host='localhost',
            port=3306,
            user='root',
            password='123',
            db= 'workf',
            charset='utf-8',
            cursorclass=pymysql.cursors.DictCursor
        )
        self.cousor = self.conn.cursor()
    def update(self,sql):
        self.cousor.execute(sql)
        self.conn.commit()
    #查询单个
    def find(self,sql):
        self.cousor.execute(sql)
        res = self.cousor.fetchone()
        return res
    #查询所有
    def find_all(self,sql):
        self.cousor.execute(sql)
        res = self.cousor.fetchall()
        return res

    #关闭
    def close(self):
        self.cousor.close()
        self.conn.close()

db1 = DB()
